package capstoneproject.dudiachi.Main;

import java.util.ArrayList;

import capstoneproject.dudiachi.Model.IslandArticleType;
import capstoneproject.dudiachi.Model.OldDistrict;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class IslandArticleTypeListAdapter extends BaseAdapter implements OnClickListener {

	private Context context;
	private ArrayList<IslandArticleType> list;
	private ArrayList<Bitmap> bitmap;
	private RelativeLayout layout;
	
	public IslandArticleTypeListAdapter(Context applicationContext,
			ArrayList<IslandArticleType> listIslandArticleType,
			ArrayList<Bitmap> bitArray) {
		this.context = applicationContext;
		this.list = listIslandArticleType;
		this.bitmap = bitArray;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return bitmap.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = convertView;
		if(v == null){
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.list_cell, null);
		}
		
		ImageView image = (ImageView) v.findViewById(R.id.image);
		image.setImageBitmap(bitmap.get(position));
		image.setTag(""+list.get(position).getiATID());
		image.setOnClickListener(this);
		layout = (RelativeLayout) v.findViewById(R.id.listLayout);
		layout.setTag(""+list.get(position).getiATID());
		layout.setOnClickListener(this);
		TextView name = (TextView) v.findViewById(R.id.name);
		name.setText(list.get(position).getiATName());
		
		TextView shortDes = (TextView) v.findViewById(R.id.shortDes);
		
		return v;
	}

	@Override
	public void onClick(View v) {
		String tag = (String) v.getTag();
		Intent intent = new Intent(context, IslandArticleActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		Bundle bundle = new Bundle();
		bundle.putSerializable("list", list);
		bundle.putString("tag", "fromIAT");
		bundle.putString("id", tag);
		intent.putExtras(bundle);
		context.startActivity(intent);
		
	}

}
